using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Ltf.Remoting.RemoteEvents;
using Ltf.Remoting.Operations;
using Ltf.Remoting.TeamFoundation;
using Microsoft.TeamFoundation.VersionControl.Client;
using System.IO;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Ltf.Remoting.Server;
using Ltf.Remoting.TFAccess;

namespace Ltf.MonitorLizard.Forms
{
	[FormType(FormTypes.RenameTarget)]

	public partial class RenameTarget : Form
	{

		private TFServerConnection connection;

		private Workspace workspace;

		private string oldpath;


		public RenameTarget(string[] pathList, LizardEventArgs args)
		{
			InitializeComponent();
			connection = ServerConnections.GetConnectionForPath(pathList[0]);
			string path = pathList[0];
			workspace = connection.GetWorkspace(path);
			string sourceItem = workspace.GetServerItemForLocalItem(path);
			oldpath = sourceItem;
			txtSourcePath.Text = Path.GetFileName( sourceItem);
			txtSourcePath.Text = txtSourcePath.Text;
		}


		
		

		private void btnOkay_Click(object sender, EventArgs e)
		{
			char[] invalidChars = Path.GetInvalidFileNameChars();
			foreach (char c in invalidChars)
			{
				if (txtTargetPath.Text.Contains(c.ToString()))
				{
					MessageBox.Show("File/folder names can not contain the '" + c.ToString() + "' charactor.", "Invalid Charactor In Name");
					return;
				}
			}

			WorkspaceOperators wso = new WorkspaceOperators(ServerConnections.GetConnectionForPath(oldpath), workspace);

			wso.PendRename(oldpath, txtTargetPath.Text);

			this.Close();
		}


		void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}



	}
}